﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;

namespace InsideDL.MISData
{
    public class DataCIBRM : DataMatrix
    {

        public DataTable GetRMTable(string p_path, string p_sht)
        {
            string sql;
            sql = string.Format("SELECT * FROM [{0}$] ", p_sht);
            return getExcelData(sql, p_path);
        }

        public bool InsertUpdate(string p_path,string p_sht)
        {
            /*
            string sql;
            sql = string.Format("SELECT * FROM [{0}$] ",p_sht);
            DataTable dt = getExcelData(sql, p_path);
            */
            string sql;
            DataTable dt = GetRMTable(p_path, p_sht);
            System.Data.Common.DbCommand cmd = getCommand();
            foreach (DataRow row in dt.Rows)
            {
                try
                {                    
                    sql = string.Format(getInsetrStatement()
                        , row[0].ToString()
                        , row[1].ToString()
                        , row[2].ToString()
                        );
                    cmd.CommandText = sql;
                    executeSQL(cmd);
                }
                catch (Exception ex)
                {
                    sql = string.Format(getUpdateStatement()
                        , row[0].ToString()
                        , row[1].ToString()
                        , row[2].ToString()
                        );
                    cmd.CommandText = sql;
                    executeSQL(cmd);
                }
            }
            
            return false;
        }

        protected string getInsetrStatement()
        {
            return "INSERT INTO RM VALUES('{0}','{1}','{2}')";
        }

        protected string getUpdateStatement()
        {
            return @"
UPDATE RM SET rm_group='{1}'
,YM='{2}'
WHERE lnac_id='{0}'
";
        }

    }


}
